import type { ModelRow } from '#/views/onlineDesign/designModel/designModel.data';

import { requestClient } from '#/api/request';

export namespace GenModelTableApi {
  export type RowTypeFetchParams = ModelRow;
  export interface IdFetchParams {
    id: string;
  }
  export interface ListFetchParams {
    [key: string]: any;
  }
  export interface PageListFetchParams {
    [key: string]: any;
    pageNo: number;
    pageSize: number;
  }
}

/**
 * 分页列表查询
 */
export async function genModelQueryPageListApi(
  params: GenModelTableApi.PageListFetchParams,
) {
  return requestClient.get('/gen/model/queryPageList', { params });
}

/**
 * 列表查询
 */
export async function genModelQueryListApi(
  params: GenModelTableApi.ListFetchParams,
) {
  return requestClient.get('/gen/model/queryList', { params });
}

/**
 * 通过ID查询
 * @param params
 */
export async function genModelQueryByIdApi(
  params: GenModelTableApi.IdFetchParams,
) {
  return requestClient.get('/gen/model/queryById', { params });
}

/**
 * 新增
 */
export async function genModelAddApi(
  params: GenModelTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/gen/model/add', params);
}

/**
 * 编辑
 */
export async function genModelEditApi(
  params: GenModelTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/gen/model/edit', params);
}

/**
 * 删除
 * @param id 主键
 */
export async function genModelDelApi(id) {
  return requestClient.delete<boolean>(`/gen/model/delete/${id}`);
}

/**
 * 批量删除删除
 * @param ids 主键
 */
export async function genModelDeleteBatchApi(ids) {
  return requestClient.delete<boolean>(`/gen/model/deleteBatchByIds/${ids}`);
}

/**
 * 是否已经存在模型名称
 * @param params modelName 模型名称
 */
export async function genModelExistModelNameApi(params) {
  return requestClient.get<boolean>(`/gen/model/existModelName`, { params });
}

/**
 * 通过数据源编码查询数据库中的表
 * @param params 主键
 */
export async function genModelQueryTableListApi(params) {
  return requestClient.get<string>(`/gen/model/queryTableList`, {
    params,
  });
}

/**
 * 同步模型结构
 * @param params 模型ID
 */
export async function genModelSyncModelApi(params) {
  return requestClient.get<string>(`/gen/model/syncModel`, {
    params,
  });
}
